package ru.kest.babymonitor;

import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;

/**
 * Class for communication between Service and activity
 */
public class Messenger {

    private static String TAG = "IPCamBabyMonitorService";

    public static String RESUME_VIDEO = "RESUME_VIDEO";
    public static String REFRESH_MENU_PANEL = "REFRESH_MENU_PANEL";

    private static Messenger instance;

    private BlockingQueue<String> messages = new LinkedBlockingQueue<String>(5);


//    private static BlockingQueue<String> messages = new SynchronousQueue<String>();

    private Messenger() { }

    public static synchronized Messenger getInstance() {
        if (instance == null) {
            instance = new Messenger();
        }
        return instance;
    }

    public synchronized void put(String msg) {
        if (!messages.offer(msg)) {
            messages.poll();
            messages.add(msg);
        }

    }

    public String get() {
        return messages.poll();
    }


}
